/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 *
 * @Original Author: jin Chen
 * @date: Apr 12, 2004$
 * @version: 1.0
 */
package edu.psu.geovista.app.dataloader.v1.actions;

import edu.psu.geovista.app.dataloader.v1.DataLoaders;
import edu.psu.geovista.app.dataloader.v1.components.PcpDataLoader;
import edu.psu.geovista.app.dataloader.v1.config.model.Project;
import edu.psu.geovista.app.vit.pub.utils.VitUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class FinalLoad100 extends BasicAction{
    public FinalLoad100() {
    }

    public FinalLoad100(String name, DataLoaders dl) {
        super(name, dl);
    }

    public void actionPerformed(ActionEvent e) {
         processInfoFromPreviousPage();
         SwingUtilities.invokeLater(new Runnable(){

             public void run() {
                 doNext();
             }
         });

    }

    private void processInfoFromPreviousPage() {
        PcpDataLoader pcp=dataloader.getPcpload();
        edu.psu.geovista.app.dataloader.v1.components.TsDataLoader ts=dataloader.getTsload();
        //ProjectType proj=wizard.getProject();


        if(wizardData.isLoadPcpdata()){
            String [] attrs=pcp.getSelectAttributeNames() ;
            wizardData.selectPcpAttrs(attrs);
        }
        if(wizardData.isLoadTsdata()){
            String [] attrs=ts.getSelectAttributeNames() ;
            wizardData.selectTsAttrs(attrs);
        }
        //wizard.setProjectCategory(Wizard.Current ); // It is no longer a new project once loaded.
        Project projectClone = wizardData.getProjectClone();
        dataloader.setCurrentProjectName(projectClone.getID());


        //To change body of created methods use File | Settings | File Templates.
    }
    private void doNext() {
        Window w = dataloader.getRootWindow();

        VitUtils.showWaitCursor(w,null);
        //JSwingUtils.showWaitCursor(dataloader.)

        try {
            dataloader.loadFinalData();
        } finally {
            VitUtils.showNormalCursor(w);
        }
    }


}
